package com.zxl.grocery.microservice.admin.rest;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zxl
 * @Description:
 * @Date: Created in 23:46 2017/10/16
 * @Modified By:
 */
@RestController
public class Test {

    @Autowired
    private EurekaClient eurekaClient;

    @Autowired
    private DiscoveryClient discoveryClient;
    /**
     * @Author: Lzx
     * @Description: 从Eureka服务器发现服务实例
     * @Params:  * @param null
     * @Date: 23:48 2017/10/16
     */
    @GetMapping("/eureka-instance")
    public String serviceUrl() {
        InstanceInfo instance = eurekaClient.getNextServerFromEureka("ADMIN-BACK", false);
        return instance.getHomePageUrl();
    }

    /**
     * @Author: Lzx
     * @Description: 本地服务实例的信息
     * @Params:  * @param null
     * @Date: 23:46 2017/10/16
     */
    @GetMapping("/instance-info")
    public ServiceInstance showInfo(){
        ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
        return localServiceInstance;
    }
}
